package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.LaborChargesMapper;
import com.gxa.zhonglong.pojo.LaborCharges;
import com.gxa.zhonglong.service.LaborChargesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("laborChargesService")
@Transactional(rollbackFor = {Throwable.class})
public class LaborChargesServiceImpl implements LaborChargesService {


    @Autowired
    private LaborChargesMapper laborChargesMapper;


    @Override
    public Boolean addLaborCharges(LaborCharges laborCharges) throws BusinessException {
        Boolean aBoolean = laborChargesMapper.addLaborCharges(laborCharges);
        if (aBoolean) {
            return  true;
        }
        throw new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteLaborCharges(List<Long> ids) throws BusinessException {
        if (laborChargesMapper.deleteLaborCharges(ids)<1) {
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }

    }

    @Override
    public Boolean updateLaborCharges(LaborCharges laborCharges) throws BusinessException {
        Boolean aBoolean = laborChargesMapper.updateLaborCharges(laborCharges);
        if (aBoolean) {
            return true;
        }
        throw new BusinessException(ExceptionCode.UPDATE_FALSE);
    }

    @Override
    public List<LaborCharges> getLaborChargesList(Integer page, Integer size) {
        List<LaborCharges> laborCharges = laborChargesMapper.selectLaborChargesList((page-1)*size, size);
        return  laborCharges;
    }
}
